Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aggregate-error

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aggregate-error

Create an error from multiple errors

  • 4.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30M
increased by3.04%
Maintainers
1
Weekly downloads
 
Created

What is aggregate-error?

The aggregate-error package is used to create an Error instance that aggregates multiple errors into a single error object. This can be useful when you have several operations that may each throw errors, and you want to collect all of those errors into a single error object that can be thrown, returned, or logged.

What are aggregate-error's main functionalities?

Aggregating multiple errors

This feature allows you to collect multiple errors into a single error object. The code sample demonstrates how to create an instance of AggregateError with an array of Error objects and then throw it.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

throw aggregatedError;

Iterating over aggregated errors

This feature allows you to iterate over the individual errors within an AggregateError instance. The code sample shows how to loop through each error using a for...of loop and log them to the console.

const AggregateError = require('aggregate-error');

const errors = [
  new Error('First error'),
  new Error('Second error')
];

const aggregatedError = new AggregateError(errors);

for (const error of aggregatedError) {
  console.error(error);
}

Other packages similar to aggregate-error

Keywords

FAQs

Package last updated on 08 May 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc